K.define('kuser.kerrlist',{
   kpartname:'日志信息管理',//模块名称
   gridid:"kerror_gridlist",//表格列表id
   addwin:"kerror_addwin",//添加弹出win id
   updwim:"kerror_updatewin",//修改弹出win id
   editFlag:undefined,
   /**
    * 初始化
    * @param me
    * @param type
    */
   init: function (me,type) {
		me.kuser_gridlist(me);
	},
	/**
	 * 渲染表格
	 * @param me
	 */
   kuser_gridlist:function(me){
	   var listid=me.gridid;
	   $("#"+listid,me.contentTarget).datagrid({
		      url:"./datalogs/searchlogslist",
		      queryParams:{},
		      title:'',
		      width:'98%',
		      rownumbers: true, //是否显示列数 
		      loadMsg: "正在加载数据...",
		      pagination:true ,
		      //pagePosition:"top",
		      fit: true,   //自适应大小
			  border:false,
			  rowTooltip: false,
			  nowrap: true,//数据长度超出列宽时将会自动截取。
			  fitColumns:true,//自动使列适应表格宽度以防止出现水平滚动。
			  singleSelect:false,
			  autoRowHeight:true,  
			  /*toolbar: [{
			  	 text:'添加',
				 iconCls: 'icon-add',
				 handler: function(){
					 me.kuser_add(me);
					 }
				},'-',{
			  	 text:'修改',
				 iconCls: 'icon-edit',
				 handler: function(){
					 me.kuser_kupiswin(me);
					}
				},'-',{
				  	 text:'删除',
					 iconCls: 'icon-edit',
					 handler: function(){
						 me.kuser_deletedata(me);
						}
					}],*/
		        columns:[[
		         /* { field:'ck',checkbox:true },*/
		          {field:'czzt',title:'状态',width:60,align:'center',formatter: function(value,row,index){	
		        	  if (value == '1') {
	                        return '成功';
		        	  }else{
		        		  return '失败';
		        	  }
		        	  return value;
		          }},
		          {field:'lxdm',title:'执行类型',width:60,align:'center',formatter: function(value,row,index){	
		        	  if (value == '1') {
	                        return '工作';
		        	  }else{
		        		  return '转换';
		        	  }
		        	  return value;
		          }},
		          {field:'zxlb',title:'执行类别',width:60,align:'center',formatter: function(value,row,index){	
		        	  if (value == '1') {
	                        return '定时执行';
		        	  }else{
		        		  return '立即执行';
		        	  }
		        	  return value;
		          }},
		          {field:'jobname',title:'工作任务名',width:80,align:'center'},
		          {field:'jobgroupname',title:'工作任务组',width:80,align:'center'},
		          {field:'kssj',title:'开始时间',width:90,align:'center',
		        	  formatter :  function(value, row, index) {
	                    if (value == null || value == '') {
	                        return '';
	                    }
	                    var dt;
	                    if (value instanceof Date) {
	                        dt = value;
	                    } else {
	                        dt = new Date(value);
	                    }
	                    return dt.format("yyyy-MM-dd hh:mm:ss");
	                }},
		          {field:'jssj',title:'结束时间',width:90,align:'center',
		        	  formatter :  function(value, row, index) {
		                    if (value == null || value == '') {
		                        return '';
		                    }
		                    var dt;
		                    if (value instanceof Date) {
		                        dt = value;
		                    } else {
		                        dt = new Date(value);
		                    }
		                    return dt.format("yyyy-MM-dd hh:mm:ss");
		                }},
		          {field:'zxbz',title:'执行步骤',width:240,align:'center',tooltip:'true'}
		      ]],
		       onLoadSuccess:function(data){  
		        $("#"+listid,me.contentTarget).datagrid('fixRowHeight');  
		    },
		    onDblClickRow :function(rowIndex,rowData){
		    	if(rowData){
		              me.kuser_update(me,rowData);
		             }
		    	}
		  }); 
		  var p = $("#"+listid,me.contentTarget).datagrid("getPager");  
		  $(p).pagination({  
		       pageSize: 10,//每页显示的记录条数，默认为10 
		       pageList: [10, 20, 30],//可以设置每页记录条数的列表  
		       beforePageText: '第',//页数文本框前显示的汉字  
		       afterPageText: '页    共 {pages} 页',  
		       displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		   }); 
	  },
	  /**
	   * 查询
	   * @param me
	   * @param formid
	   */
	  selectkuser:function(me,formid){
	     var listid=me.gridid;
	     var ktitle=$("#jobname",'#'+formid,me.contentTarget).val();//名称
		 var param = {"jobname" :ktitle};
		 $('#'+listid,me.contentTarget).datagrid("load",param);
	},
	repalceval:function(kval){
		if(kval=="null" || !kval){
			return "";
		}
		return kval;
	},
	/**
	 * 弹出添加界面
	 * @param me
	 */
	kuser_add:function(me){
		 K.tpl({
				tpl: "resources/template/kuser/kuserment_win.html",
				success: function(html,data){
					var dialogs = $('<div></div>').dialog({
						title: '添加信息',
						width:'900',
					    height:'500',
					    iconCls: 'icon-edit',
					    content:html,
					    modal: true,
					    fit: true, 
					    resizable: true,  //控制窗体拉伸
		                /*minimizable: true,//控制最小化
		                maximizable: true, //控制最大化  */
					    buttons:[{text:'发布',iconCls:"icon-save",handler:function(){
					    	me.upresult_save(me,dialogs,1);
					    }},{text:'存草稿',iconCls:"icon-save",handler:function(){
					    	me.upresult_save(me,dialogs,0);
					    }},{text:'取消',iconCls:"icon-no",handler:function(){
					            	  $(dialogs).dialog('destroy');
					            	  UE.getEditor('editor').destroy();
					            	  }}
					                ],
					    closed: false,
					    cache: false,
					    onClose : function() {
		                     $(this).dialog('destroy');
		                     UE.getEditor('editor').destroy();
		                 },
		                 onOpen:function(){
		                	 me.onwinsize();
		                 },
		                 onResize:function(){
		                	 me.onwinsize();
		                 },
		                 onMove:function(){
		                	 me.onwinsize();
		                 }
					});
					var ue = UE.getEditor('editor');
				}
			}); 
		 
  },
  kuser_kupiswin:function(me){
		var rows = $("#kerror_gridlist",me.contentTarget).datagrid('getSelections');
		if(rows.length!=1){
			 K.kmessager('提示','选中一条要调整的表单');  
			 return false;
		}
		var kid=rows[0];
	    me.kuser_update(me,kid);
	
	},
  kuser_deletedata:function(me){
	    var rows = $("#kerror_gridlist",me.contentTarget).datagrid('getSelections');
		if(rows.length<=0){
			 K.kmessager('提示','至少要选择一条要删除的表单');  
			 return false;
		}
	   var arrid=[];
	   $.each(rows,function(i,v){
		   arrid.push(v.kid);
	   });
	   
	   $.messager.confirm('提醒','确定要删除该记录吗?',function(isok){
		    if (isok){
		    	 $.ajax({
					  type:"post",
					  url:"kmaincountents/showdeletemsg",
					  dataType:"json",
					  data:{"arrids":arrid.join(",")},
					  success: function(result) {
						  if(result){
							 var sucess=result.sucess;
							 $("#"+me.gridid,me.contentTarget).datagrid('reload');
							 K.kmessager('提示','删除成功！');
						  }else{
							  K.kmessager('提示','删除失败！');
						  }
					  }
		    });
		   }
		 });
  },
  /**
   * 修改弹出界面
   */
	kuser_update:function(me,rowData){
	 K.tpl({
			tpl: "static/resources/template/kuser/kerrlist_win.html",
			//url:"kmaincountents/showmsgById",
			//data:{"kid":kid},
			before: function(data){
				return rowData;
			},
			success: function(html,data){
				console.log(data);
				var dialogs = $('<div></div>').dialog({
					title: '查看信息',
					width:'900',
				    height:'450',
				    iconCls: 'icon-edit',
				    content:html,
				    modal: true,
				    //fit: true, 
				    resizable: true,  //控制窗体拉伸
	               /* minimizable: true,//控制最小化
	                maximizable: true, //控制最大化*/
				    buttons:[
				   /* {text:'发布',iconCls:"icon-save",handler:function(){
				    	me.upresult_save(me,dialogs,1);
				    }},{text:'存草稿',iconCls:"icon-save",handler:function(){
				    	me.upresult_save(me,dialogs,0);
				    }},*/
				    {text:'关闭',iconCls:"icon-no",handler:function(){
	            	    $(dialogs).dialog('destroy');
	            	  }}
	                ],
				    closed: false,
				    cache: false,
				    onOpen:function(){
	                	 me.onwinsize();
	                 },
	                 onResize:function(){
	                	 me.onwinsize();
	                 },
	                 onMove:function(){
	                	 me.onwinsize();
	                 },
				    onClose : function() {
	                     $(this).dialog('destroy');
	                 }
				});			       
			}
		}); 
	 juicer.register('decorate', me.repalceval);
	},
	onwinsize:function(){
		 $(".window").css("z-index","1001");
         $(".window-shadow").css("z-index","900");
         $(".window-mask").css("z-index","900");
	},
  //保存数据
 upresult_save:function(me,dialogs,ktype){
	  $.messager.progress();
	  //var msg=UE.getEditor('editor').getContent();
	  //$("#kstart").val(ktype);
	  //$("#editor").val(msg);
	  $('#kerror_myform',dialogs).form('submit', {
	  	url: "kmaincountents/showsavemsg",
	  	onSubmit: function(){
	  		var isValid = $(dialogs).form('validate');
	  		if (!isValid){
	  			$.messager.progress('close');	
	  		}
	  		return isValid;	
	  	},
	  	error:function (data, status, e){   
	  		 K.kmessager('提示','出现异常！');
		},  
	  	success: function(result){
	  		$.messager.progress('close');
	  		if(result){
	  			 dialogs.dialog('destroy');
	  			 //UE.getEditor('editor').destroy();
				 $("#"+me.gridid,me.contentTarget).datagrid('reload');
				 K.kmessager('提示','数据提交成功！');
			  }else{
				  K.kmessager('提示','数据提交失败！');
			  }
	  	  }
	  });
 }
}, true);